package problem287;

//287.寻找重复数
//https://leetcode.cn/problems/find-the-duplicate-number/?envType=study-plan-v2&envId=top-100-liked

class Solution {
    public int findDuplicate(int[] nums) {
        int n = nums.length;
        int fast = 0, slow = 0;
        while(true) {
            fast = nums[fast];
            fast = nums[fast];
            slow = nums[slow];
            if(fast == slow) {
                break;
            }
        }
        slow = 0;
        while(true) {
            fast = nums[fast];
            slow = nums[slow];
            if(fast == slow) return fast;
        }
    }
}